﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ToolPositioningInternal.CApTPIGraphicsDrawer
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.Generic;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ToolPositioningInternal;

public class CApTPIGraphicsDrawer
{
  private List<TxManipulator> _manipulators = new List<TxManipulator>();

  public List<TxManipulator> Manipulators => this._manipulators;

  private TxManipulator CreateManipulator()
  {
    using (TxManipulatorCreationData manipulatorCreationData = new TxManipulatorCreationData(nameof (CApTPIGraphicsDrawer) + this.Manipulators.Count.ToString(), new TxTransformation()))
    {
      TxManipulator manipulator = TxApplication.ActiveDocument.PhysicalRoot.CreateManipulator(manipulatorCreationData);
      this._manipulators.Add(manipulator);
      return manipulator;
    }
  }

  public void RemoveContour(TxManipulator manip)
  {
    this._manipulators.Remove(manip);
    this.DeleteContour(manip);
  }

  private void DeleteContour(TxManipulator manip)
  {
    manip.RemoveAllElements();
    TxObjectEx.ForceDeletion((ITxObject) manip);
  }

  private void CreateLineElement(
    TxManipulator manip,
    TxVector startPoint,
    TxVector endPoint,
    TxColor color)
  {
    TxManipulatorLineElementData manipulatorLineElementData1 = new TxManipulatorLineElementData(new TxTransformation(), startPoint, endPoint);
    ((TxManipulatorElementData) manipulatorLineElementData1).Color = color;
    manipulatorLineElementData1.LineWidth = 2.0;
    ((TxManipulatorElementData) manipulatorLineElementData1).AlwaysOnTop = false;
    ((TxManipulatorElementData) manipulatorLineElementData1).Pickable = true;
    TxManipulatorLineElementData manipulatorLineElementData2 = manipulatorLineElementData1;
    manip.AddElement((TxManipulatorElementData) manipulatorLineElementData2);
  }

  private void CreatePointElement(
    TxManipulator manip,
    TxVector point,
    TxColor color,
    double pointSize)
  {
    TxManipulatorSphereElementData sphereElementData1 = new TxManipulatorSphereElementData(new TxTransformation(point, (TxTransformation.TxTransformationType) 1), pointSize);
    ((TxManipulatorElementData) sphereElementData1).Color = color;
    ((TxManipulatorElementData) sphereElementData1).AlwaysOnTop = false;
    ((TxManipulatorElementData) sphereElementData1).Pickable = true;
    TxManipulatorSphereElementData sphereElementData2 = sphereElementData1;
    manip.AddElement((TxManipulatorElementData) sphereElementData2);
  }

  public TxManipulator DrawContour(TxContour c, TxColor color)
  {
    TxManipulator manipulator = this.CreateManipulator();
    for (int index = 1; index < c.Points.Count; ++index)
      this.CreateLineElement(manipulator, c.Points[index - 1], c.Points[index], color);
    return manipulator;
  }

  public TxManipulator DrawContour(
    List<TxVector> points,
    TxColor color,
    TxVector point1,
    TxVector point2,
    TxVector point3,
    double pointSize)
  {
    TxManipulator manip = (TxManipulator) null;
    if (points.Count > 0)
    {
      manip = this.CreateManipulator();
      if (TxManipulator.op_Inequality(manip, (ITxObject) null))
      {
        for (int index = 1; index < points.Count; ++index)
          this.CreateLineElement(manip, points[index - 1], points[index], color);
        if (TxVector.op_Inequality(point1, (TxVector) null))
          this.CreatePointElement(manip, point1, TxColor.TxColorRed, pointSize);
        if (TxVector.op_Inequality(point2, (TxVector) null))
          this.CreatePointElement(manip, point2, TxColor.TxColorYellow, pointSize);
        if (TxVector.op_Inequality(point3, (TxVector) null))
          this.CreatePointElement(manip, point3, TxColor.TxColorBlue, pointSize);
      }
    }
    return manip;
  }

  public void DrawContourPoints(
    TxManipulator manip,
    List<TxVector> points,
    TxColor color,
    double pointSize)
  {
    if (!TxManipulator.op_Inequality(manip, (ITxObject) null) || points.Count <= 0)
      return;
    this.CreatePointElement(manip, points[0], color, pointSize);
    for (int index = 1; index < points.Count; ++index)
      this.CreatePointElement(manip, points[index], color, pointSize);
  }

  public void Clear()
  {
    foreach (TxManipulator manipulator in this._manipulators)
      this.DeleteContour(manipulator);
    this._manipulators.Clear();
  }
}
